<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>库存异常</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:150px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 150px;}
		.inputdiv{display:flex;height: 38px;line-height: 38px;}
		.inputdiv i{position:absolute;right:10px;}
		.layui-table-cell .layui-table-link {color: #ff6a08!important;}}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">分店仓库</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="branch_no" id="branch_no" autocomplete="off" value="" placeholder="分店仓库必选" class="layui-input" onfocus="showBranchs()">
									<i class="layui-icon layui-icon-home"></i>
								</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品分类</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="class_no" id="item_cls" placeholder="" autocomplete="off" class="layui-input" onfocus="selectCls()">
								<i class="layui-icon layui-icon-list"></i>
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品品牌</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="brand_no" id="brand" placeholder="" autocomplete="off" class="layui-input" onfocus="selectBrand()">
								<i class="layui-icon layui-icon-vercode"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">供应商名</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="sp_no" id="supplier" placeholder="" autocomplete="off" class="layui-input" onfocus="showSupplier()">
								<i class="layui-icon layui-icon-username"></i>
							</div>
						</div>
						
					</div>
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">商品货号</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="item_no" id="item_no" placeholder="" autocomplete="off" class="layui-input" onfocus="selectGoods()">
									<i class="layui-icon layui-icon-cart-simple"></i>
								</div>
							</div>
							
							<div class="layui-form-item layui-inline">
								<label class="layui-form-label">商品名称</label>
								<div class="layui-input-inline">
									<input type="text" name="item_name" placeholder="" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="stock-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
					</div>
					
					
					</div>
					
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body" id="stock-body">
				<table id="stock-table" lay-filter="stock-table"></table>
			</div>
		</div>
		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script src="__STATIC__/js/admin/common.js"></script>
		<script>
			var branch_no="";
			var _layerIndex=null;
			var operator_url="{:U('Controls/operators')}";
			var supplier_url="{:U('Controls/suppliers')}";
			var pos_url="{:U('Controls/poslists')}";
			var items_url="{:U('Controls/items')}";
			var itemcls_url="{:U('Controls/itemcls')}";
			var brand_url="{:U('Controls/brands')}";
			var branchs_url="{:U('Controls/branchs')}";
			
			layui.use(['table', 'form', 'jquery','common','laydate'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				let laydate = layui.laydate;

				let DATA_PATH = "/{$MODULE_NAME}/stock/warning/";

				let cols = [
					[
						{
							title: '序号',
							field: 'rowIndex',
							align: 'left',
							width: 80
						},
						{
							title: '门店编号',
							field: 'branch_no',
							align: 'left',
							width: 100
						},
						{
							title: '门店名称',
							field: 'branch_name',
							align: 'left',
							width: 100
						},
						{
							title: '商品货号',
							field: 'item_no',
							align: 'left',
							width: 180
						},
						{
							title: '商品名称',
							field: 'item_name',
							align: 'left',
							width: 180
						},
						{
							title: '助记码',
							field: 'item_rem',
							align: 'left',
							width: 120
						},
						{
							title: '库存指标上限',
							field: 'max_qty',
							align: 'center',
							width: 150
						},
						{
							title: '库存指标下限',
							field: 'min_qty',
							align: 'center',
							width: 150
						},
						{
							title: '商品类别',
							field: 'item_clsno',
							align: 'center',
							width: 100
						},
						{
							title: '类别名称',
							field: 'item_clsno',
							align: 'center',
							width: 100
						},
						{
							title: '单位',
							field: 'unit_no',
							align: 'left',
							width: 100
						},
						{
							title: '规格',
							field: 'item_size',
							align: 'center',
							width: 100
						},
						{
							title: '库存数量',
							field: 'stock_qty',
							align: 'center',
							width: 100
						},
						{
							title: '供应商名称',
							field: 'sp_company',
							align: 'center',
							width: 100
						}
					]
				]

				table.render({
					elem: '#stock-table',
					url: DATA_PATH+"search",
					page: true,
					cols: cols,
					height:600,
					skin: 'line',
					toolbar: '',
					defaultToolbar: [],
					done:function(res, curr, count){
						var _width=$("#stock-body").width();
						$("#stock-table").css("width", _width);
					}
				});
				
				form.on('submit(stock-query)', function(data) {
					table.reload('stock-table', {
						where: data.field,
						page:{curr:1}
					})
					return false;
				});
				
				//显示分店选择框
				window.showBranchs=function(){
					_layerIndex=openWin("分店仓库选择",branchs_url,"800px","600px");
				}
				
				//门店选择后的回调函数
				window.callBackBranch=function(data){
					
					var arr=new Array();
					for(var i in data){
						arr.push(data[i]['branch_no']);
					}
					
					$("#branch_no").val(arr.join(","));
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
					_layerIndex=null;
				}
				
				//显示操作员选择框
				window.showOperators=function(){
					var oval=$("#operator").val();
					
					if(_layerIndex==null||oval==''){
						_layerIndex=openWin("营业员选择",operator_url,"800px","600px");
					}
				}
				
				//操作员选择后的回调函数
				window.callBackOprator=function(data){
					
					$("#operator").val(data[0]['oper_id']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}
				
				//显示POS机选择框
				window.showPos=function(){
					var oval=$("#posid").val();
					
					if(_layerIndex==null||oval==''){
						_layerIndex=openWin("POS机选择",pos_url,"800px","600px");
					}
				}
				
				//POS机选择后的回调函数
				window.callBackPos=function(data){
					
					$("#posid").val(data[0]['posid']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}
				
				//选择商品窗口
				window.selectGoods=function(){
					_layerIndex=openWin("商品选择",items_url,"1100px","600px");
				}
				
				//商品选择后的回调函数
				window.callBack=function(data){
					
					$("#item_no").val(data[0]['item_no']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//选择商品分类窗口
				window.selectCls=function(){
					_layerIndex=openWin("商品分类选择",itemcls_url,"800px","600px");
				}
				
				//商品分类选择后的回调函数
				window.callBackItemcls=function(data){
					
					$("#item_cls").val(data[0]['item_clsno']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//选择商品品牌窗口
				window.selectBrand=function(){
					_layerIndex=openWin("商品品牌选择",brand_url,"800px","600px");
				}
				
				//商品品牌选择后的回调函数
				window.callBackBrand=function(data){
					
					$("#brand").val(data[0]['code_id']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//显示供应商选择框
				window.showSupplier=function(){
					_layerIndex=openWin("供应商选择",supplier_url,"800px","600px");
				}
				
				//供应商选择后的回调函数
				window.callBackSupplier=function(data){
					
					$("#supplier").val(data[0]['sp_no']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}
				
				window.refresh = function(param) {
					table.reload('stock-table');
				}
			})
		</script>
	</body>
</html>
